package com.yt.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.yt.util.CommonResult;
import com.yt.util.MyBlockHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Classname PayController
 * @Description
 * @Date 2021/10/29 19:21
 * @Create by 杨涛
 */
@RestController
@Slf4j

public class PayController {

    @RequestMapping("/byres")
    @SentinelResource(value = "byResources", blockHandler = "handlerException")
    public CommonResult<Date> byResources() {
        return new CommonResult<>(200, "byres ok", new Date());
    }

    public CommonResult<Date> handlerException(BlockException be) {
        log.warn("执行熔断方法");
        return new CommonResult<>(404, "byres error", new Date());
    }

    @GetMapping("/byone")
    @SentinelResource(value = "byone", blockHandlerClass = MyBlockHandler.class, blockHandler = "handlerException")
    public CommonResult byone() {
        return new CommonResult<>(200, "byone ok", new Date());
    }

    @GetMapping("/bytwo")
    @SentinelResource(value = "bytwo", blockHandlerClass = MyBlockHandler.class, blockHandler = "handlerException2")
    public CommonResult bytwo() {
        return new CommonResult<>(200, "bytwo ok", new Date());
    }
}
